<?php


class b2c_finder_sales_rule_order{
    var $column_control = '操作';
    var $detail_basic = '查看';
    var $addon_cols = "from_time,to_time";

    public function __construct($app) {
        $this->app = $app;
    }


    var $column_state = "状态";
    var $column_state_width = 80;
    var $column_state_order = 90;
    function column_state($row)
    {
        $start_time = $row[$this->col_prefix.'from_time'];
        $end_time = $row[$this->col_prefix.'to_time'];
        $status = $row[$this->col_prefix.'status'];

        $button = '';
        if($status=='false') {
            $button .= ' <font color="#999">已关闭</font>';
        }elseif($start_time > time()){
            $button .= ' <font color="#999">未开始</font>';
        }elseif($end_time < time()){
            $button .= ' <font color="#999">已过期</font>';
        }else{
            $button .= ' <font color=green>活动中</font>';
        }
        return $button;
    }

    public function row_style($row)
    {
        $start_time = $row[$this->col_prefix.'from_time'];
        $end_time = $row[$this->col_prefix.'to_time'];
        $status = $row[$this->col_prefix.'status'];

        if($status=='false' or $start_time > time() or $end_time < time()){
            return 'list-close';
        }else{
            return '';
        }
    }

    function column_control($row){
        return '<a href="index.php?app=b2c&ctl=admin_sales_order&act=edit&p[0]='.$row['rule_id'].'&finder_id='.$_GET['_finder']['finder_id'].'" target="_blank">'.app::get('b2c')->_('编辑').'</a>';
    }
    function detail_basic($id){
        $arr = $this->app->model('sales_rule_order')->dump($id);
        $render = $this->app->render();


        //会员等级
        if($arr['member_lv_ids']) {
            $member_lv_id = explode(',', $arr['member_lv_ids']);
            $member = $this->app->model('member_lv')->getList('*', array('member_lv_id'=>$member_lv_id) );
            if(count($member_lv_id)>count($member)) {
                $member[] = array('name'=>app::get('b2c')->_('非会员'));
            }
            $render->pagedata['member'] = $member;
        }

        //生效平台
        if($arr['apply_platform']) {
            $apply_platform = explode(',', $arr['apply_platform']);
            $platfromArr = array('1'=>'PC端','2'=>'触屏端');
            $platfrom = '';

            if($apply_platform) {
                foreach($apply_platform as $value){
                    $platform[] = $platfromArr[$value];
                }
            }
            $render->pagedata['platform'] = $platform;
        }

        //过滤条件
        if($arr['conditions']) {
            if($arr['c_template']) {
                $render->pagedata['conditions'] = kernel::single($arr['c_template'])->tpl_name;
            }
        }

        //优惠方案
        if($arr['action_solution']) {
            if($arr['s_template']) {
            	$o = kernel::single($arr['s_template']);
            	$o->setString($arr['action_solution'][$arr['s_template']]);
                $render->pagedata['action_solution'] = $o->getString();
            }
        }
        $render->pagedata['rules'] = $arr;
        return $render->fetch('admin/sales/finder/order.html');
    }
}
?>
